export class PageInfo {
  totalElements: number;
  data: object;
  pageCount: number;
  pagesArr: Array<number>;
  currentPage: number;
  totalPages: number;


  constructor(totalElements: number = 0, data: object = null, pageCount: number = 0, pagesArr: Array<number> = Array(0),
              currentPage: number = 0, totalpages: number = 0) {
    this.totalElements = totalElements;
    this.data = data;
    this.pageCount = pageCount;
    this.pagesArr = pagesArr;
    this.currentPage = currentPage;
    this.totalElements = totalElements;
  }
}

export function generatePageInfo(pageInfo: PageInfo, httpResultData: object) {
  httpResultData['headers'].get('ReturnStatus');
  pageInfo.totalElements = Number(httpResultData['headers']['headers'].get('x-total-count')[0]);
  const pageCount = Math.floor(pageInfo.totalElements / 12) + 1;
  pageInfo.pageCount = pageCount > 10 ? 10 : pageCount;
  pageInfo.pagesArr = Array(pageInfo.pageCount).fill(0).map((value, index) => index + 1);
  pageInfo.data = httpResultData['body'];
  pageInfo.currentPage = 1;
  pageInfo.totalPages = pageCount;
}
